#include <vector>
#include <queue>
using namespace std;

// 柠檬水找零
class Solution {
public:
    bool lemonadeChange(vector<int>& bills) {
        int five = 0, ten = 0;
        for (int x : bills)
        {
            if (x == 5) five++;
            else if (x == 10)
            {
                if (five) ten++, five--;
                else return false;
            }
            else
            {
                if (ten && five) ten--, five--; // 贪心，优先找10块
                else if (five > 2) five -= 3;
                else return false;
            }
        }
        return true;
    }
};

// 将数组和减半的最少操作次数
class Solution {
public:
    int halveArray(vector<int>& nums) {
        double sum = 0;
        priority_queue<double> pq;
        for (int x : nums) 
        {
            pq.push(x);
            sum += x;
        }
        sum /= 2.0;
        int count = 0;
        while (sum > 0)
        {
            count++;
            double d = pq.top() / 2.0;
            pq.pop();
            sum -= d;
            pq.push(d);
        }
        return count;
    }
};